package linestrategy

import (
	"codejy/analysis/lineanalysis"
	"codejy/globalfunc"
	"codejy/store"
	"codejy/structdef"
)

type CoreFunStrategy struct {
}

func init() {
	RegisterStrategy(&CoreFunStrategy{})
}
func (n CoreFunStrategy) getId() int {
	return lineanalysis.CoreFun
}

func (n CoreFunStrategy) Execute(threadStore *structdef.ThreadStore) {
	codeLine := threadStore.Code.LineContent
	//去掉core&
	code := codeLine[5:]
	currentInstanceAddress := threadStore.CurrentInstanceAddress
	prop, _ := store.GetInstanceProp(threadStore, currentInstanceAddress)
	typeName, _ := prop["@TYPENAME@"] //获取实例的类型名称
	interfaces := globalfunc.ExecuteFunc("SubFunctionCallNameAndParam", code).([]interface{})
	funName, funParams := interfaces[0].(string), interfaces[1].([]string)
	funParams = globalfunc.ExecuteFunc("ParamTransition", threadStore, funParams).([]string)
	globalfunc.ExecuteFunc("ExecuteTypeDefault", threadStore, currentInstanceAddress, typeName.Value, funName, funParams)

}
